package utils

import (
	"flag"
	"reflect"
)

type Command struct {
	Params map[string]interface{}
}

var singleCommand Command

func InitCommand() {
	if !reflect.DeepEqual(singleCommand, Command{}) {
		return
	}
	singleCommand = Command{
		Params: make(map[string]interface{}),
	}
	syncDb := flag.Bool("syncDb", false, "syncDb")
	flag.Parse()
	singleCommand.SetParam("syncDb", *syncDb)
}

// GetCommand 获取命令行结构体
func GetCommand() Command {
	return singleCommand
}

func (c *Command) SetParam(key string, val interface{}) {
	c.Params[key] = val
}

func (c *Command) GetParam(key string) interface{} {
	if v, ok := c.Params[key]; ok {
		return v
	}
	return nil
}
